package com.zhixing.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhixing.order.domain.entity.Order;
import com.zhixing.order.domain.entity.OrderCompleteInfo;
import com.zhixing.order.domain.entity.OrderReceiveInfo;
import com.zhixing.order.domain.entity.OrderSendInfo;
import com.zhixing.order.domain.enums.OrderStatus;
import com.zhixing.order.domain.vo.OrderPayInfoVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    @Select("select id, user_id, city_code, start_location, end_location, start_longitude, start_latitude, " +
            "estimate_distance, estimate_duration, estimate_fee, order_status from t_order where id = #{orderId}")
    OrderSendInfo getOrderSendInfo(Long orderId);

    List<Integer> getDriverOrderCount(List<Integer> driverIds, LocalDate now, OrderStatus orderStatus);

    @Select("select id, order_number, driver_id, city_code, start_location, start_longitude, start_latitude, " +
            "order_status from t_order where id = #{orderId}")
    OrderReceiveInfo getReceiveOrderInfo(Long orderId);

    @Select("select id, start_location, end_location, start_longitude, start_latitude, end_longitude, end_latitude, " +
            "real_polyline, real_fee, order_status, start_time from t_order where id = #{orderId}")
    OrderPayInfoVO getOrderPayInfo(Long orderId);

    @Select("select real_fee from t_order where id = #{orderId} and user_id = #{userId} and order_status = #{orderStatus}")
    BigDecimal getRealFee(Long orderId, Integer userId, OrderStatus orderStatus);

    @Select("select user_id, driver_id, real_distance, real_payment, start_time from t_order where id = #{orderId} and order_status = #{orderStatus}")
    OrderCompleteInfo getOrderCompleteInfo(Long orderId, OrderStatus orderStatus);

    @Select("select count(*) from t_order where driver_id = #{driverId} and date(end_time) = #{now} and order_status = #{orderStatus}")
    Integer getTodayOrderCount(Integer driverId, LocalDate now, OrderStatus orderStatus);
}
